﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
//using System.Data.SqlClient;
//using System.Data.Odbc;
//using System.Configuration;
//using System.Net.NetworkInformation;

using ECS.BLL.Entity;
using ECS.BLL.Component;
using ECS.Framework;

namespace E_ICS.E_ICS
{
    public partial class frmWHInventory : Form
    {
        #region private properties
        Main.frmMain2 main;

        DataSet dtInventory = null;
        DataSet dtLocationDetail = null;
        string MAWB_id, slip_id, MAWB, HAWB, display_flight_date, display_flight_number, partial_seq, Piece, net, last_slip_stored_date, last_slip_retrieved_date, inventory_status, active_pick;
        string newdate;
        string stvalidationMMHH = "PASS";
        string location, inn;
        DataTable TInventory = new DataTable();
        int index = 0;
        SearchInfo compData = null;

        //SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["con3"].ConnectionString);
        //SqlConnection sqlCon2 = new SqlConnection(ConfigurationManager.ConnectionStrings["con3"].ConnectionString);
        //string appId = ConfigurationManager.AppSettings["appID"];
        //string device = ConfigurationManager.AppSettings["device"];
        private readonly System.Threading.SynchronizationContext syncContext = System.Threading.SynchronizationContext.Current;
        #endregion

        #region form events
        public frmWHInventory(Main.frmMain2 _main)
        {
            InitializeComponent();
            main = _main;
        }
        private void frmWHInventory_Load(object sender, EventArgs e)
        {
            try
            {
                this.toolStripStatusLabel2.Text = GlobalVariable.userName;
                dpkFromDate.Enabled = false;
                dpkToDate.Enabled = false;
                txtDateTo.Enabled = false;
                txtDateFrom.Enabled = false;
                imbCD.Enabled = false;
                imbPD.Enabled = false;
                imbPH.Enabled = false;
                dgvWHInventory.RowHeadersWidth = 80;
                compData = new SearchInfo();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void chkDataSearch_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (chkDataSearch.Checked)
                {
                    dpkFromDate.Enabled = true;
                    dpkToDate.Enabled = true;
                    txtDateTo.Enabled = true;
                    txtDateFrom.Enabled = true;
                    imbCD.Enabled = true;
                    imbPD.Enabled = true;
                    imbPH.Enabled = true;
                }
                else
                {
                    dpkFromDate.Enabled = false;
                    dpkToDate.Enabled = false;
                    txtDateTo.Enabled = false;
                    txtDateFrom.Enabled = false;
                    imbCD.Enabled = false;
                    imbPD.Enabled = false;
                    imbPH.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                //LoadData();
                //SetGridData();
                btnLocationDetail.Enabled = false;
                lblTotal.Text = "0";
                dgvWHInventory.DataSource = null;
                dgvLocationDetail.DataSource = null;
                DateTime date;
                if (!string.IsNullOrEmpty(txtflightdate.Text))
                {
                    if (DateTime.TryParse(txtflightdate.Text, out date) == false)
                    {
                        CommonMessageBox.ShowMessageWarning("Flightdate format is not correct.");
                        txtflightdate.Focus();
                        return;
                    }
                }
                if (chkDataSearch.Checked)
                {
                    validationMMHH(txtDateFrom);
                    validationMMHH(txtDateTo);
                    if (stvalidationMMHH.Equals("PASS"))
                    {
                        
                        SearchWHInventoryWithDate();
                        //setRowNumber(dgvWHInventory);
                    }

                    else

                    //คืนค่า
                    {
                        stvalidationMMHH = "PASS";
                    }
                }
                else
                {
                    SearchWHInventory();
                    //setRowNumber(dgvWHInventory);
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void btnLocationDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvWHInventory.RowCount > 0)
                {
                    GetValuedgvWHInventory(index);
                    E_ICS.frmLocAdjust la = new E_ICS.frmLocAdjust(dtLocationDetail);
                    if (la.ShowDialog() == DialogResult.Yes)
                    {
                        showdgvLocationDetail();
                        //setRowNumber(dgvLocationDetail);
                    }
                    //la.Show();
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void btnAccDetail_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvWHInventory.RowCount > 0)
                {
                    GetValuedgvWHInventory(index);

                    E_ICS.frmWeightSlipDisplay wsd = new E_ICS.frmWeightSlipDisplay(main);
                    wsd.Show();
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void dpkFlightDate_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                txtflightdate.Text = String.Format("{0:ddMMMyy}", dpkFlightDate.Value).ToUpper();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void dgvWHInventory_Sorted(object sender, EventArgs e)
        {
            try
            {
                setRowNumber(dgvWHInventory);
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }

        }

        private void dgvLocationDetail_Sorted(object sender, EventArgs e)
        {
            try
            {
                setRowNumber(dgvLocationDetail);
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void dgvLocationDetail_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                dgvLocationDetail.CurrentRow.Selected = true;
                if (dgvLocationDetail.CurrentRow.Selected)
                {
                    btnLocationDetail.Enabled = true;
                }
                else
                {
                    btnLocationDetail.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void imbPD_Click(object sender, EventArgs e)
        {
            try
            {
                set_PDtime_to_dpk();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void imbCD_Click(object sender, EventArgs e)
        {
            try
            {
                set_CDtime_to_dpk();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void imbPH_Click(object sender, EventArgs e)
        {
            try
            {
                set_PHtime_to_dpk();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        private void btnClearAll_Click_1(object sender, EventArgs e)
        {
            try
            {
                txtCarrier.Text = "";
                txtDateFrom.Text = "00:00";
                txtDateTo.Text = "23:59";
                txtFltNo.Text = "";
                txtHAWB.Text = "";
                txtLocation.Text = "";
                txtPrefix.Text = "";
                txtScaleID.Text = "";
                txtSerial.Text = "";
                txtSlipNumber.Text = "";
                chkDataSearch.Checked = false;
                dgvWHInventory.DataSource = null;
                lblTotal.Text = "0";

                dgvLocationDetail.DataSource = null;
                dpkFlightDate.Value = DateTime.Now;
                dpkFromDate.Value = DateTime.Now;
                dpkToDate.Value = DateTime.Now;
                dgvLocationDetail.ClearSelection();
                btnLocationDetail.Enabled = false;
                txtflightdate.Text = "";
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void dgvWHInventory_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                index = e.RowIndex;
                if (e.RowIndex >= 0 && e.ColumnIndex >= 0 && dgvWHInventory.Rows.Count > 0)
                {
                    //dgvWHInventory.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

                    dgvWHInventory.Rows[index].Selected = true;
                    if (dgvWHInventory.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                    {
                        MAWB_id = dgvWHInventory.Rows[e.RowIndex].Cells[0].Value.ToString();
                        slip_id = dgvWHInventory.Rows[e.RowIndex].Cells[1].Value.ToString();
                        showdgvLocationDetail();
                        setRowNumber(dgvLocationDetail);
                        //countLvocationTotal();
                        countLoc();
                        if (e.ColumnIndex == dgvWHInventory.Columns["Pick"].Index)
                        {
                            if (dgvWHInventory.Rows[index].Cells[2].Value != DBNull.Value && Convert.ToBoolean(dgvWHInventory.Rows[index].Cells[2].Value))
                            {
                                dgvWHInventory.Rows[index].Cells[2].Value = false;
                                updateActive_pickNo();

                            }
                            else
                            {
                                if (dgvWHInventory.Rows[index].Cells[2].Value != DBNull.Value)
                                {
                                    dgvWHInventory.Rows[index].Cells[2].Value = true;
                                    updateActive_pickYes();
                                }

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }

        private void dgvWHInventory_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                index = e.RowIndex;
                if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
                {
                    //dgvWHInventory.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    dgvWHInventory.Rows[index].Cells[2].Value = true;
                    dgvWHInventory.Rows[index].Selected = true;
                    if (dgvWHInventory.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                    {
                        MAWB_id = dgvWHInventory.Rows[e.RowIndex].Cells[0].Value.ToString();
                        //slip_id = dgvWHInventory.Rows[e.RowIndex].Cells[1].Value.ToString();
                        dgvWHInventory.ClearSelection();
                        dgvWHInventory.Rows[index].Cells[2].Value = false;
                        updateActive_pickNo();
                        MAWB_id = "";
                        slip_id = "";

                    }
                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
        }
        #endregion

        #region private methods
        private void GetValuedgvWHInventory(int index)
        {
            //try
            //{
            ViewEditWHInventory.MAWB_ID = dgvWHInventory.Rows[index].Cells[0].Value.ToString();
            ViewEditWHInventory.slip_id = dtInventory.Tables[0].Rows[index]["slip_number"].ToString();
            ViewEditWHInventory.MAWB = dgvWHInventory.Rows[index].Cells[3].Value.ToString().Trim();
            ViewEditWHInventory.HAWB = dgvWHInventory.Rows[index].Cells[5].Value.ToString();
            ViewEditWHInventory.Flight_No = dgvWHInventory.Rows[index].Cells[6].Value.ToString();
            ViewEditWHInventory.Flight_Date = dgvWHInventory.Rows[index].Cells[7].Value.ToString();
            ViewEditWHInventory.Partial_Acc = dgvWHInventory.Rows[index].Cells[4].Value.ToString();
            ViewEditWHInventory.Piece = dgvWHInventory.Rows[index].Cells[8].Value.ToString();
            ViewEditWHInventory.Weight = dgvWHInventory.Rows[index].Cells[9].Value.ToString();
            ViewEditWHInventory.Last_Stored = dgvWHInventory.Rows[index].Cells[10].Value.ToString();
            ViewEditWHInventory.Last_Retrieved = dgvWHInventory.Rows[index].Cells[11].Value.ToString();
            ViewEditWHInventory.Status = dgvWHInventory.Rows[index].Cells[12].Value.ToString();
            ViewEditWHInventory.scale_id = dtInventory.Tables[0].Rows[index]["scale_id"].ToString();
            ViewEditWHInventory.Nature_of_Goods = dtInventory.Tables[0].Rows[index]["Nature_of_Goods"].ToString();
            //}
            //catch (Exception)
            //{

            //    // throw;
            //}
        }

        //ตรวจจับรูปแบบวันที่
        public void ConvertDate(string dateinput)
        {
            string dd = dateinput.Substring(8, 2);
            string mm = dateinput.Substring(5, 2);
            string yyyy = dateinput.Substring(0, 4);

            int yyyyint = Convert.ToInt32(yyyy);

            if (yyyyint > 2200)
            {
                yyyyint = yyyyint - 543;
            }

            else
            {
                //
            }

            string yyyyst = yyyyint.ToString();
            newdate = "" + yyyyst + "-" + mm + "-" + dd + "";

        }

        private void SearchWHInventory()
        {
            dtInventory = new DataSet();
            //SqlCommand cmd = new SqlCommand();
            try
            {
                //sqlCon.Open();
                //SqlDataAdapter daInventory = new SqlDataAdapter(cmd);
                //// Int32 rowsAffected;

                //cmd.CommandText = "usp_SearchWHInventory";
                //cmd.CommandType = CommandType.StoredProcedure;
                //cmd.Connection = sqlCon;
                //cmd.Parameters.AddWithValue("@in_vchApplicationID", appId);
                //cmd.Parameters.AddWithValue("@in_dtFlightDate", dpkFlightDate.Value);
                //cmd.Parameters.AddWithValue("@in_vchDevice", GlobalVariable.Device);
                //cmd.Parameters.AddWithValue("@in_vchUserID", GlobalVariable.userName);
                //cmd.Parameters.AddWithValue("@in_vchMAWB", txtPrefix.Text + "-" + txtSerial.Text);
                //cmd.Parameters.AddWithValue("@in_vchMAWBPrefix", "%" + txtPrefix.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchMAWBSerial", "%" + txtSerial.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchHAWB", "%" + txtHAWB.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchCarrier", "%" + txtCarrier.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchFlightNumber", "%" + txtFltNo.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchAgentCode", "");
                //cmd.Parameters.AddWithValue("@in_vchScaleID", "%" + txtScaleID.Text);
                //cmd.Parameters.AddWithValue("@in_vchSlipNumber", "%" + txtSlipNumber.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchShipmentype", "");
                //daInventory.Fill(dtInventory, "Inventory ");

                SearchCriteria criteria = new SearchCriteria();
                criteria.AppId = GlobalVariable.user.ApplicationID;
                if (!string.IsNullOrEmpty(txtflightdate.Text))
                {
                    criteria.FlightDate = Convert.ToDateTime(txtflightdate.Text);
                }
                criteria.Device = GlobalVariable.user.Device;
                criteria.UserId = GlobalVariable.user.UserID;
                criteria.MAWB = txtPrefix.Text + "-" + txtSerial.Text;
                criteria.MAWBPrefix = "%" + txtPrefix.Text + "%";
                criteria.MAWBSerial = "%" + txtSerial.Text + "%";
                criteria.HAWB = "%" + txtHAWB.Text + "%";
                criteria.Carrier = "%" + txtCarrier.Text + "%";
                criteria.FlightNo = "%" + txtFltNo.Text + "%";
                criteria.AgentCode = "";
                criteria.ScaleId = "%" + txtScaleID.Text;
                criteria.SlipNo = "%" + txtSlipNumber.Text + "%";
                criteria.SipmentType = string.Empty;

                dtInventory = compData.SearchWhInventory(criteria);

                DataTable dtInventory_TB = CreateWHInventory_TB(dtInventory);
                dgvWHInventory.DataSource = dtInventory_TB;
                setRowNumber(dgvWHInventory);
               // setdgvdisplay();
               
                if (dgvWHInventory.RowCount > 0)
                {
                    setdgvdisplay();
                    dgvWHInventory.Rows[0].Selected = true;
                }
                else
                {
                    CommonMessageBox.ShowMessageWarning("Data not found");
                }

                if (dtInventory_TB != null && dtInventory_TB.Rows.Count > 0)
                {
                    MAWB_id = dgvWHInventory.Rows[0].Cells[0].Value == null ? string.Empty : dgvWHInventory.Rows[0].Cells[0].Value.ToString();
                    slip_id = dgvWHInventory.Rows[0].Cells[1].Value == null ? string.Empty : dgvWHInventory.Rows[0].Cells[1].Value.ToString();
                }
                else
                {
                    MAWB_id = string.Empty;
                    slip_id = string.Empty;
                }
                //if (!string.IsNullOrEmpty(MAWB_id) && !string.IsNullOrEmpty(slip_id))
                //{
                //    MAWB_id = null;
                //    slip_id = null; 
                //}
                viewInventory();
                countLoc();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
            //finally
            //{
            //    if (sqlCon != null && sqlCon.State == ConnectionState.Open)
            //    {
            //        sqlCon.Close();
            //    }
            //}
        }

        private void setdgvdisplay()
        {
            dgvWHInventory.Columns[4].Width = 50;
            dgvWHInventory.Columns[6].Width = 70;
            dgvWHInventory.Columns[7].Width = 70;
            dgvWHInventory.Columns[8].Width = 50;
            dgvWHInventory.Columns[9].Width = 50;
            dgvWHInventory.Columns[12].Width = 70;
            dgvWHInventory.Columns[2].Width = 50;
            dgvWHInventory.RowHeadersWidth = 60;
            dgvWHInventory.Columns[0].Visible = false;
            dgvWHInventory.Columns[1].Visible = false;
        }

        private void SearchWHInventoryWithDate()
        {
            //SqlCommand cmd = new SqlCommand();
            dtInventory = new DataSet();
            try
            {
                //// Int32 rowsAffected;

                //cmd.CommandText = "usp_SearchWHInventoryWithDate";
                //cmd.CommandType = CommandType.StoredProcedure;
                //cmd.Connection = sqlCon;
                //cmd.Parameters.AddWithValue("@in_vchApplicationID", appId);
                //if (txtflightdate.Text.Equals(string.Empty))
                //{

                //}
                //cmd.Parameters.AddWithValue("@in_dtFlightDate", dpkFlightDate.Value);
                //cmd.Parameters.AddWithValue("@in_vchDevice", GlobalVariable.Device);
                //cmd.Parameters.AddWithValue("@in_vchUserID", GlobalVariable.userName);
                //cmd.Parameters.AddWithValue("@in_vchMAWB", txtPrefix.Text + "-" + txtSerial.Text);
                //cmd.Parameters.AddWithValue("@in_vchMAWBPrefix", "%" + txtPrefix.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchMAWBSerial", "%" + txtSerial.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchHAWB", "%" + txtHAWB.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchCarrier", "%" + txtCarrier.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchFlightNumber", "%" + txtFltNo.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchAgentCode", "");
                //cmd.Parameters.AddWithValue("@in_vchScaleID", "%" + txtScaleID.Text);
                //cmd.Parameters.AddWithValue("@in_vchSlipNumber", "%" + txtSlipNumber.Text + "%");
                //cmd.Parameters.AddWithValue("@in_vchShipmentype", "");

                //DateTime dateFrom = dpkFromDate.Value;
                //string datedpkfrom = dateFrom.Date.ToString("yyyy-MM-dd");


                //ConvertDate(datedpkfrom);
                //string allfromdate = newdate + " " + txtDateFrom.Text;
                //cmd.Parameters.AddWithValue("@in_dtFromDateTime", allfromdate);



                ////DateTime myDate = DateTime.ParseExact(allfromdate, "yyyy-MM-dd HH:mm",
                ////                           System.Globalization.CultureInfo.InvariantCulture);



                //DateTime dateto = dpkToDate.Value;
                //string datedpkto = dateto.Date.ToString("yyyy-MM-dd");
                //ConvertDate(datedpkto);
                //string alltodate = newdate + " " + txtDateTo.Text;
                //cmd.Parameters.AddWithValue("@in_dtToDateTime", alltodate);


                //sqlCon.Open();

                //SqlDataAdapter daInventory = new SqlDataAdapter(cmd);
                //daInventory.Fill(dtInventory, "Inventory");

                SearchCriteria criteria = new SearchCriteria();
                criteria.AppId = GlobalVariable.user.ApplicationID;
                if (!string.IsNullOrEmpty(txtflightdate.Text))
                {
                    //criteria.FlightDate = dpkFlightDate.Value;
                    criteria.FlightDate = Convert.ToDateTime(txtflightdate.Text);
                }
                criteria.Device = GlobalVariable.user.Device;
                criteria.UserId = GlobalVariable.user.UserID;
                criteria.MAWB = txtPrefix.Text + "-" + txtSerial.Text;
                criteria.MAWBPrefix = "%" + txtPrefix.Text + "%";
                criteria.MAWBSerial = "%" + txtSerial.Text + "%";
                criteria.HAWB = "%" + txtHAWB.Text + "%";
                criteria.Carrier = "%" + txtCarrier.Text + "%";
                criteria.FlightNo = "%" + txtFltNo.Text + "%";
                criteria.AgentCode = "";
                criteria.ScaleId = "%" + txtScaleID.Text;
                criteria.SlipNo = "%" + txtSlipNumber.Text + "%";
                criteria.SipmentType = string.Empty;

                string datedpkfrom = dpkFromDate.Value.Date.ToString("yyyy-MM-dd");
                ConvertDate(datedpkfrom);
                string allfromdate = newdate + " " + txtDateFrom.Text;

                string datedpkto = dpkToDate.Value.Date.ToString("yyyy-MM-dd");
                ConvertDate(datedpkto);
                string alltodate = newdate + " " + txtDateTo.Text;


                dtInventory = compData.SearchWhInventoryWithDateRange(criteria, allfromdate, alltodate);
                DataTable dtInventory_TB = CreateWHInventory_TB(dtInventory);
                
                dgvWHInventory.DataSource = dtInventory_TB;
                if (dtInventory_TB.Rows.Count>0)
                {
                    
                    setdgvdisplay();
                    // dgvWHInventory.Columns[0].Visible = false;
                    //dgvWHInventory.Columns[1].Visible = false;
                    if (dgvWHInventory.Rows.Count > 0)
                    {
                        dgvWHInventory.Rows[0].Selected = true;
                    }

                    
                    viewInventory();
                    countLoc();
                    setRowNumber(dgvWHInventory);
                }
                else
                {
                    CommonMessageBox.ShowMessageWarning("Data not found");
                }
                //sqlCon.Close();
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);
            }
            //finally
            //{
            //    if (sqlCon != null && sqlCon.State == ConnectionState.Open)
            //    {
            //        sqlCon.Close();
            //    }
            //}
        }

        private DataTable CreateWHInventory_TB(DataSet ds)
        {
            TInventory = new DataTable();
            ///////////create head column/////////////////

            TInventory.Columns.Add("MAWB_ID", typeof(string));
            TInventory.Columns.Add("slip_id", typeof(string));
            TInventory.Columns.Add("Pick", typeof(bool));

            TInventory.Columns.Add("MAWB", typeof(string));
            TInventory.Columns.Add("Partial Sequence", typeof(string));
            TInventory.Columns.Add("HAWB", typeof(string));

            TInventory.Columns.Add("Flight No", typeof(string));
            TInventory.Columns.Add("Flight Date", typeof(string));

            TInventory.Columns.Add("Piece", typeof(string));
            TInventory.Columns.Add("Weight", typeof(string));

            TInventory.Columns.Add("Last Stored", typeof(string));
            TInventory.Columns.Add("Last Retrieved", typeof(string));
            TInventory.Columns.Add("Status", typeof(string));

            ///////////////////////////////////////////////
            //int row = dtInventory.Tables[0].Rows.Count;
            //for (int i = 0; i < row; i++)
            //{
            //    MAWB_id = dtInventory.Tables[0].Rows[i]["mawb_id"].ToString().Trim();
            //    slip_id = dtInventory.Tables[0].Rows[i]["slip_id"].ToString().Trim();
            //    MAWB = dtInventory.Tables[0].Rows[i]["display_mawb"].ToString().Trim();
            //    partial_seq = dtInventory.Tables[0].Rows[i]["partial_seq"].ToString().Trim();
            //    HAWB = dtInventory.Tables[0].Rows[i]["hawb"].ToString().Trim();

            //    display_flight_date = dtInventory.Tables[0].Rows[i]["display_flight_date"].ToString().Trim();
            //    display_flight_number = dtInventory.Tables[0].Rows[i]["display_flight_number"].ToString().Trim();

            //    Piece = dtInventory.Tables[0].Rows[i]["total_piece_count"].ToString().Trim();
            //    net = dtInventory.Tables[0].Rows[i]["total_net"].ToString().Trim();
            //    last_slip_stored_date = dtInventory.Tables[0].Rows[i]["last_slip_stored_date"].ToString().Trim();
            //    last_slip_retrieved_date = dtInventory.Tables[0].Rows[i]["last_slip_retrieved_date"].ToString().Trim();

            //    inventory_status = dtInventory.Tables[0].Rows[i]["inventory_status"].ToString().Trim();
            //    active_pick = dtInventory.Tables[0].Rows[i]["active_pick"].ToString().Trim();

            //    if (active_pick.Equals("YES"))
            //    {
            //        TInventory.Rows.Add(MAWB_id, slip_id, true, MAWB, partial_seq, HAWB, display_flight_number, display_flight_date, Piece, net, last_slip_stored_date, last_slip_retrieved_date, inventory_status);
            //    }
            //    else if (active_pick.Equals("NO"))
            //    {
            //        TInventory.Rows.Add(MAWB_id, slip_id, false, MAWB, partial_seq, HAWB, display_flight_number, display_flight_date, Piece, net, last_slip_stored_date, last_slip_retrieved_date, inventory_status);
            //    }

            //}

            int row = ds.Tables[0].Rows.Count;
            for (int i = 0; i < row; i++)
            {
                MAWB_id = ds.Tables[0].Rows[i]["mawb_id"].ToString().Trim();
                slip_id = ds.Tables[0].Rows[i]["slip_id"].ToString().Trim();
                MAWB = ds.Tables[0].Rows[i]["display_mawb"].ToString().Trim();
                partial_seq = ds.Tables[0].Rows[i]["partial_seq"].ToString().Trim();
                HAWB = ds.Tables[0].Rows[i]["hawb"].ToString().Trim();

                display_flight_date = ds.Tables[0].Rows[i]["display_flight_date"].ToString().Trim();
                display_flight_number = ds.Tables[0].Rows[i]["display_flight_number"].ToString().Trim();

                Piece = ds.Tables[0].Rows[i]["total_piece_count"].ToString().Trim();
                net = ds.Tables[0].Rows[i]["total_net"].ToString().Trim();
                last_slip_stored_date = Utilities.DateFormatting_dd_mm_yy_time(ds.Tables[0].Rows[i]["last_slip_stored_date"]);
                   
                   // ds.Tables[0].Rows[i]["last_slip_stored_date"].ToString().Trim();
                last_slip_retrieved_date = Utilities.DateFormatting_dd_mm_yy_time(ds.Tables[0].Rows[i]["last_slip_retrieved_date"]);
                    //ds.Tables[0].Rows[i]["last_slip_retrieved_date"].ToString().Trim();

                inventory_status = ds.Tables[0].Rows[i]["inventory_status"].ToString().Trim();
                active_pick = ds.Tables[0].Rows[i]["active_pick"].ToString().Trim();

                if (active_pick.Equals("YES"))
                {
                    TInventory.Rows.Add(MAWB_id, slip_id, true, MAWB, partial_seq, HAWB, display_flight_number, display_flight_date, Piece, net, last_slip_stored_date, last_slip_retrieved_date, inventory_status);
                }
                else if (active_pick.Equals("NO"))
                {
                    TInventory.Rows.Add(MAWB_id, slip_id, false, MAWB, partial_seq, HAWB, display_flight_number, display_flight_date, Piece, net, last_slip_stored_date, last_slip_retrieved_date, inventory_status);
                }

            }
            return TInventory;
        }

        private void set_PHtime_to_dpk()
        {
            //เช็ค Datetime nows            
            DateTime Dateto = DateTime.Now;

            // เอาเวลาปัจจุบัน ลบ 1ชั่วโมง(เพราะจะหาค่าชั่วโมงที่แล้ว
            System.TimeSpan duration = new System.TimeSpan(0, -1, 0, 0);
            System.DateTime dateFromnow = Dateto.Add(duration);

            //เอาวันทีใส่ datepicker
            dpkFromDate.Value = dateFromnow;
            dpkToDate.Value = Dateto;

            //เอาเวลาใส่ datepicker

            //แปลง datetime now เป็น string   
            string sttimeFromnow = dateFromnow.ToString("HH:mm");
            string sttimetonow = Dateto.ToString("HH:mm");
            //เอาstring ลง textbox
            txtDateFrom.Text = sttimeFromnow;
            txtDateTo.Text = sttimetonow;

        }

        private void set_CDtime_to_dpk()
        {
            //เช็ค Datetime nows            
            DateTime Dateto = DateTime.Now;

            //เอาวันทีใส่ datepicker
            dpkFromDate.Value = Dateto;
            dpkToDate.Value = Dateto;

            //เอาเวลาใส่ datepicker

            //แปลง datetime now เป็น string   
            string sttimeFromnow = "00:00";
            string sttimetonow = Dateto.ToString("HH:mm");
            //เอาstring ลง textbox
            txtDateFrom.Text = sttimeFromnow;
            txtDateTo.Text = sttimetonow;

        }

        private void set_PDtime_to_dpk()
        {

            //เช็ค Datetime nows            
            DateTime Dateto = DateTime.Now;


            // เอาเวลาปัจจุบัน ลบ 1ชั่วโมง(เพราะจะหาค่าชั่วโมงที่แล้ว
            System.TimeSpan duration = new System.TimeSpan(-1, 0, 0, 0);
            System.DateTime dateFromnow = Dateto.Add(duration);

            //เอาวันทีใส่ datepicker
            dpkFromDate.Value = dateFromnow;
            dpkToDate.Value = dateFromnow;

            //เอาเวลาใส่ datepicker

            //แปลง datetime now เป็น string   
            string sttimeFromnow = "00:00";
            string sttimetonow = "23:59";
            //เอาstring ลง textbox
            txtDateFrom.Text = sttimeFromnow;
            txtDateTo.Text = sttimetonow;

        }
        /// <summary>
        /// validate date format
        /// </summary>
        /// <param name="stfromdate"></param>

        public void validationMMHH(TextBox stfromdate)
        {

            //ดักว่าต้อง pass ก่อนหน้าถึงมีสิทธิแทนที่ค่า   stvalidationMMHH
            if (stvalidationMMHH.Equals("PASS"))
            {

                // string stfromdate = txtDateFrom.Text;
                if (stfromdate.Text.Length == 5)
                {
                    string hh = stfromdate.Text.Substring(0, 2);
                    string mm = stfromdate.Text.Substring(3, 2);
                    string center = stfromdate.Text.Substring(2, 1);


                    int inthh;
                    int intmm;

                    if (int.TryParse(hh, out inthh))
                    {
                        if (inthh >= 0 && inthh <= 23)
                        {
                            if (int.TryParse(mm, out intmm))
                            {
                                if (intmm >= 0 && intmm <= 59)
                                {
                                    if (center.Equals(":"))
                                    {
                                        stvalidationMMHH = "PASS";
                                    }
                                    else
                                    {
                                        CommonMessageBox.ShowMessageWarning("กรุณาใส่ที่แบ่งชั่วโมงและนาทีให้เป็น :  เท่านั้น");
                                        stvalidationMMHH = "NO PASS";
                                        stfromdate.Focus();
                                    }
                                }
                                else
                                {
                                    CommonMessageBox.ShowMessageWarning("กรุณานาทีให้ถูกต้อง 0-59 เท่านั้น");
                                    stvalidationMMHH = "NO PASS";
                                    stfromdate.Focus();
                                }
                            }
                            else
                            {
                                CommonMessageBox.ShowMessageWarning("กรุณาใส่นาทีตัวเลขเท่านั้น");
                                stvalidationMMHH = "NO PASS";
                                stfromdate.Focus();
                            }
                        }

                        else
                        {
                            CommonMessageBox.ShowMessageWarning("กรุณาชั่วโมงให้ถูกต้อง 0-23 เท่านั้น");
                            stvalidationMMHH = "NO PASS";
                            stfromdate.Focus();
                        }
                    }

                    else
                    {
                        CommonMessageBox.ShowMessageWarning("กรุณาใส่ชั่วโมงตัวเลขเท่านั้น");
                        stvalidationMMHH = "NO PASS";
                        stfromdate.Focus();
                    }
                }


                else
                {
                    CommonMessageBox.ShowMessageWarning("กรุณาตรวจสอบความยาวของรูปแบบการกรอกข้อมูล");
                    stvalidationMMHH = "NO PASS";
                    stfromdate.Focus();
                }

                //จบดักว่าต้อง pass ก่อนหน้าถึงมีสิทธิแทนที่ค่า   stvalidationMMHH
            }

            else
            {
                //ไม่ต้องทำอะไร
            }

        }


        /// <summary>
        /// show warehouse location detail
        /// </summary>
        public void showdgvLocationDetail()
        {
            //try
            //{
            //SqlCommand cmd = new SqlCommand("select location,piece_count,inventory_id,location_id from v_hht_inventory where slip_id=@slip_id and mawb_id=@mawb_id", sqlCon);
            //cmd.Parameters.AddWithValue("@slip_id", slip_id);
            //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
            //sqlCon2.Open();

            //SqlDataAdapter daLocationDetail = new SqlDataAdapter(cmd);
            //dtLocationDetail = new DataSet();
            //daLocationDetail.Fill(dtLocationDetail, "LocationDetail");

            SearchCriteria criteria = new SearchCriteria();
            criteria.SlipId = slip_id;
            criteria.MAWBId = MAWB_id;
            dtLocationDetail = compData.SearchWhLocationDetail(criteria);
            DataTable dtLocationDetail_TB = CreateLocationDetail_TB(dtLocationDetail);
            dgvLocationDetail.DataSource = dtLocationDetail_TB;
            setRowNumber(dgvLocationDetail);
            //sqlCon2.Close();

            //}
            //catch (Exception)
            //{
            //    //
            //}
            //finally
            //{
            //    if (sqlCon != null && sqlCon.State == ConnectionState.Open)
            //    {
            //        sqlCon.Close();
            //    }
            //}

        }

        private DataTable CreateLocationDetail_TB(DataSet ds)
        {
            DataTable TLocationDetail = new DataTable();
            ///////////create head column/////////////////
            TLocationDetail.Columns.Add("Location", typeof(string));
            TLocationDetail.Columns.Add("In", typeof(string));





            ///////////////////////////////////////////////
            int row = dtLocationDetail.Tables[0].Rows.Count;
            for (int i = 0; i < row; i++)
            {
                location = dtLocationDetail.Tables[0].Rows[i]["location"].ToString().Trim();
                inn = dtLocationDetail.Tables[0].Rows[i]["piece_count"].ToString().Trim();



                TLocationDetail.Rows.Add(location, inn);
            }
            return TLocationDetail;
        }

        //public void countLvocationTotal()
        //{
        //    SearchCriteria criteria = new SearchCriteria();
        //    criteria.SlipId = slip_id;
        //    criteria.MAWBId = MAWB_id;
        //    lblTotal.Text = compData.CountLocationTotal(criteria).ToString("#,##0");

        //    //SqlCommand cmd = new SqlCommand("select sum(piece_count) as total from v_hht_inventory where slip_id=@slip_id and mawb_id=@mawb_id", sqlCon);
        //    //SqlDataAdapter DA = new SqlDataAdapter(cmd);
        //    //cmd.Parameters.AddWithValue("@slip_id", slip_id);
        //    //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
        //    //sqlCon.Open();
        //    //SqlDataReader reader2 = cmd.ExecuteReader();
        //    //if (reader2.Read())
        //    //{
        //    //    lblTotal.Text = reader2["total"].ToString();
        //    //}
        //    //else
        //    //{

        //    //}
        //    //sqlCon.Close();
        //}

        public void updateActive_pickYes()
        {
            //SqlCommand cmd = new SqlCommand("update t_eics_mawb set active_pick='YES'where  mawb_id=@mawb_id", sqlCon);
            //SqlDataAdapter DA = new SqlDataAdapter(cmd);
            ////cmd.Parameters.AddWithValue("@slip_id", slip_id);
            //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
            //sqlCon.Open();
            //cmd.ExecuteNonQuery();
            //sqlCon.Close();
            if (dgvWHInventory.Rows.Count > 0)
            {
                SearchCriteria criteria = new SearchCriteria();
                criteria.MAWBId = MAWB_id;
                criteria.SlipId = slip_id;
                compData.UpdatePickItem(criteria);
            }
        }

        public void updateActive_pickNo()
        {
            if (dgvWHInventory.Rows.Count > 0)
            {
                SearchCriteria criteria = new SearchCriteria();
                criteria.MAWBId = MAWB_id;
                criteria.SlipId = slip_id;
                compData.UpdateReturnItem(criteria);
            }
            //SqlCommand cmd = new SqlCommand("update t_eics_mawb set active_pick='NO'where  mawb_id=@mawb_id", sqlCon);
            //SqlDataAdapter DA = new SqlDataAdapter(cmd);
            ////cmd.Parameters.AddWithValue("@slip_id", slip_id);
            //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
            //sqlCon.Open();
            //cmd.ExecuteNonQuery();
            //sqlCon.Close();
        }

        private void setRowNumber(DataGridView dgv)
        {
            // dgvWeight_Disp.
            //dgv.RowHeadersWidth = 100;
            //dgvWeight_Disp.Columns[-1].HeaderText = "No";

            foreach (DataGridViewRow row in dgv.Rows)
            {
                //if (row.Index == dgv.Rows.Count - 1)
                //{
                //    row.HeaderCell.Value = "";
                //}
                //else
                {
                    row.HeaderCell.Value = String.Format("{0}", row.Index + 1);
                }
            }
        }

        private void viewInventory()
        {
            //try
            //{
            SearchCriteria criteria = new SearchCriteria();
            criteria.MAWBId = MAWB_id;
            criteria.SlipId = slip_id;
            dtLocationDetail = compData.SearchInventory(criteria);

            //SqlCommand cmd = new SqlCommand("select location,piece_count,inventory_id,location_id from v_hht_inventory where slip_id=@slip_id and mawb_id=@mawb_id", sqlCon2);
            //cmd.Parameters.AddWithValue("@slip_id", slip_id);
            //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
            //sqlCon2.Open();
            //SqlDataAdapter daLocationDetail = new SqlDataAdapter(cmd);
            //dtLocationDetail = new DataSet();
            //daLocationDetail.Fill(dtLocationDetail, "LocationDetail");

            DataTable dtLocationDetail_TB = CreateLocationDetail_TB(dtLocationDetail);
            dgvLocationDetail.DataSource = dtLocationDetail_TB;
            setRowNumber(dgvLocationDetail);
            //sqlCon2.Close();

            //}
            //catch (Exception)
            //{

            //    //
            //}

        }

        private void countLoc()
        {
            //try
            //{
            SearchCriteria criteria = new SearchCriteria();
            criteria.SlipId = slip_id;
            criteria.MAWBId = MAWB_id;
            lblTotal.Text = compData.CountLocationTotal(criteria).ToString("#,##0");
            //lblTotal.Text =

            //SqlCommand cmd = new SqlCommand("select sum(piece_count) as total from v_hht_inventory where slip_id=@slip_id and mawb_id=@mawb_id", sqlCon);
            //SqlDataAdapter DA = new SqlDataAdapter(cmd);
            //cmd.Parameters.AddWithValue("@slip_id", slip_id);
            //cmd.Parameters.AddWithValue("@mawb_id", MAWB_id);
            //SqlDataReader reader2 = cmd.ExecuteReader();
            //if (reader2.Read())
            //{
            //    lblTotal.Text = reader2["total"].ToString();
            //}

            //}
            //catch (Exception)
            //{

            //    //
            //}

        }

        #endregion

        //#region show waiting screen
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="state"></param>
        //private void ThreadWork(object state)
        //{
        //    if (dtInventory != null)
        //    {
        //        dtInventory.Clear();
        //    }
        //    dtInventory = new DataSet();
        //    bool isDateSearch = false;
        //    SearchCriteria criteria = new SearchCriteria();
        //    try
        //    {
        //        isDateSearch = (bool)state;
        //        if (isDateSearch)
        //        {

        //            criteria.AppId = GlobalVariable.user.ApplicationID;
        //            criteria.FlightDate = dpkFlightDate.Value;
        //            criteria.Device = GlobalVariable.user.Device;
        //            criteria.UserId = GlobalVariable.user.UserID;
        //            criteria.MAWB = txtPrefix.Text + "-" + txtSerial.Text;
        //            criteria.MAWBPrefix = "%" + txtPrefix.Text + "%";
        //            criteria.MAWBSerial = "%" + txtSerial.Text + "%";
        //            criteria.HAWB = "%" + txtHAWB.Text + "%";
        //            criteria.Carrier = "%" + txtCarrier.Text + "%";
        //            criteria.FlightNo = "%" + txtFltNo.Text + "%";
        //            criteria.AgentCode = "";
        //            criteria.ScaleId = "%" + txtScaleID.Text;
        //            criteria.SlipNo = "%" + txtSlipNumber.Text + "%";
        //            criteria.SipmentType = string.Empty;

        //            string datedpkfrom = dpkFromDate.Value.Date.ToString("yyyy-MM-dd");
        //            ConvertDate(datedpkfrom);
        //            string allfromdate = newdate + " " + txtDateFrom.Text;

        //            string datedpkto = dpkToDate.Value.Date.ToString("yyyy-MM-dd");
        //            ConvertDate(datedpkto);
        //            string alltodate = newdate + " " + txtDateTo.Text;

        //            dtInventory = compData.SearchWhInventoryWithDateRange(criteria, allfromdate, alltodate);

        //        }
        //        else
        //        {
        //            //SearchCriteria criteria = new SearchCriteria();
        //            criteria.AppId = GlobalVariable.user.ApplicationID;
        //            if (!string.IsNullOrEmpty(txtflightdate.Text))
        //            {
        //                criteria.FlightDate = dpkFlightDate.Value;
        //            }
        //            criteria.Device = GlobalVariable.user.Device;
        //            criteria.UserId = GlobalVariable.user.UserID;
        //            criteria.MAWB = txtPrefix.Text + "-" + txtSerial.Text;
        //            criteria.MAWBPrefix = "%" + txtPrefix.Text + "%";
        //            criteria.MAWBSerial = "%" + txtSerial.Text + "%";
        //            criteria.HAWB = "%" + txtHAWB.Text + "%";
        //            criteria.Carrier = "%" + txtCarrier.Text + "%";
        //            criteria.FlightNo = "%" + txtFltNo.Text + "%";
        //            criteria.AgentCode = "";
        //            criteria.ScaleId = "%" + txtScaleID.Text;
        //            criteria.SlipNo = "%" + txtSlipNumber.Text + "%";
        //            criteria.SipmentType = string.Empty;

        //            dtInventory = compData.SearchWhInventory(criteria);
        //        }

        //        DataTable dtInventory_TB = CreateWHInventory_TB(dtInventory);

        //        this.Invoke(new Action(() =>
        //        {
        //            dgvWHInventory.DataSource = dtInventory_TB;

        //            if (dgvWHInventory.RowCount > 0)
        //            {
        //                dgvWHInventory.Columns[0].Visible = false;
        //                dgvWHInventory.Columns[1].Visible = false;
        //                dgvWHInventory.Rows[0].Selected = true;
        //                setRowNumber(dgvWHInventory);
        //            }

        //        }));
                
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //    }
        //    finally
        //    {
        //        FinishLoad(null);
        //    }
        //}

        //private void SetGridData()
        //{
        //    if (chkDataSearch.Checked)
        //    {
        //        validationMMHH(txtDateFrom.Text);
        //        validationMMHH(txtDateTo.Text);
        //        if (!stvalidationMMHH.Equals("PASS"))
        //        {
        //            return;
        //        }
        //    }
        //    dgvLocationDetail.DataSource = null;
        //    showWaitIndicator();
        //    btnLocationDetail.Enabled = false;
        //    //System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Test));
        //    System.Threading.Thread t = new System.Threading.Thread(ThreadWork);
        //    t.IsBackground = true;
        //    //t.Start();

        //    t.Start(chkDataSearch.Checked);
        //}
        ////private void Test()
        ////{
        ////    //this.Invoke(new Action(() =>
        ////    //{
        ////        try
        ////        {
        ////            if (chkDataSearch.Checked)
        ////            {
        ////                validationMMHH(txtDateFrom.Text);
        ////                validationMMHH(txtDateTo.Text);
        ////                if (stvalidationMMHH.Equals("PASS"))
        ////                {
        ////                    dgvLocationDetail.DataSource = null;
        ////                    SearchWHInventoryWithDate();
        ////                    //setRowNumber(dgvWHInventory);
        ////                }
        ////            }
        ////            else
        ////            {
        ////                SearchWHInventory();
        ////                //setRowNumber(dgvWHInventory);
        ////            }
        ////            //System.Threading.Thread.Sleep(3000);
        ////            FinishLoad(null);
        ////            //syncContext.Post(FinishLoad, null);
        ////        }
        ////        catch (Exception ex)
        ////        {
        ////            CommonMessageBox.ShowMessageError(ex);
        ////        }
        ////    //}));
        ////}
        ////private void LoadData()
        ////{
        ////    //validate data

        ////    showWaitIndicator();
        ////    btnLocationDetail.Enabled = false;
        ////    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Test));
        ////    t.IsBackground = true;
        ////    t.Start();
        ////    //Test();
        ////    //FinishLoad();
        ////}

        //private Control overlay = null;

        //private Tuple<Panel, Label> createProgressControls(Size size)
        //{
        //    var progreassBar = new ProgressBar()
        //    {
        //        Style = ProgressBarStyle.Marquee,
        //        Size = new System.Drawing.Size(200, 40),
        //        MarqueeAnimationSpeed = 40
        //    };
        //    var m_panel = new Panel();
        //    m_panel.Size = progreassBar.Size;
        //    m_panel.Location = new Point((size.Width - m_panel.Width) / 2, (size.Height - m_panel.Height) / 2);
        //    m_panel.BackColor = Color.FromArgb(0, 0, 0, 0);
        //    //var m_styles = AppCode.Utils.CommonConfiguration.getstyleSheets();
        //    var m_lblCaption = new Label()
        //    {
        //        Text = "Please wait, now processing...",
        //        AutoSize = false,
        //        Size = new Size(200, this.Font.Height * 5 / 4), //m_styles.FormalFont.Height * 5 / 4),
        //        Location = new Point(m_panel.Location.X, m_panel.Location.Y + m_panel.Size.Height),
        //        BackColor = Color.SteelBlue,
        //        ForeColor = Color.White,
        //        Font = this.Font, //AppCode.Utils.CommonConfiguration.getstyleSheets().FormalFont,
        //        TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        //    };
        //    m_panel.Controls.Add(progreassBar);
        //    return Tuple.Create(m_panel, m_lblCaption);
        //}

        //private void showWaitIndicator()
        //{
        //    this.Cursor = Cursors.WaitCursor;
        //    //this.radPanelReport.Hide();
            
        //    var m_waitIndicator = new Panel();
            
        //    m_waitIndicator.Dock = DockStyle.Fill;
        //    var m_controls = this.createProgressControls(this.ClientSize); //WaitIndicator.OverlayTarget.createProgressControls(this.ClientSize);
        //    m_waitIndicator.Controls.Add(m_controls.Item1);
        //    m_waitIndicator.Controls.Add(m_controls.Item2);
        //    m_controls.Item1.BringToFront();
        //    m_controls.Item2.BringToFront();
        //    //this.SuspendLayout();
        //    this.Controls.Add(m_waitIndicator);
            
        //    // set Anchor to None after everything was done to make the content maintain its center position
        //    m_controls.Item1.Anchor = AnchorStyles.None;
        //    m_controls.Item2.Anchor = AnchorStyles.None;
            
        //    ////
        //    this.overlay = m_waitIndicator;
        //    //this.noDataShown = false;
            
        //    this.overlay.BringToFront();
        //    //this.ResumeLayout();
        //}

        //private void removeOverlay()
        //{
        //    if (this.overlay != null) this.Controls.Remove(this.overlay);
        //}
        //private void FinishLoad(object state)
        //{
        //    //this.Cursor = Cursors.Default;
        //    //removeOverlay();

        //    //if (this.InvokeRequired)
        //    //{
        //    this.Invoke(new Action(() =>
        //    {
        //        this.Cursor = Cursors.Default;
        //        this.removeOverlay();
        //    }));
        //    //}
        //    //else
        //    //{
        //    //    //this.textBox1.Text = text;
        //    //    this.Cursor = Cursors.Default;
        //    //    removeOverlay();
        //    //}

        //}
        //#endregion
    }
}
